package com.vincent.sciinfo.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vincent.sciinfo.pojo.Project;
import com.vincent.sciinfo.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectServer;

    @RequestMapping("/show_project")
    public List<Project> selectProject(@RequestParam  int ope, @RequestParam String teacherId){
        return projectServer.selectProject(ope, teacherId);
    }

    @RequestMapping("/add_project")
    public int insertProject(@RequestBody(required = false) Project project){
        return projectServer.insertProject(project);
    }

    @RequestMapping("/select_one_project")
    public Project selectOneProject(@RequestBody(required = false) Project project){
        return projectServer.selectOneProject(project);
    }

    @RequestMapping("/selectCheckAndRemoveProject")
    public PageInfo selectCheckAndRemoveProject(@RequestParam Integer pn, @RequestParam Integer pageSize){
        PageHelper.startPage(pn, pageSize);
        List<Project> projects = projectServer.selectCheckAndRemoveProject();
        PageInfo page = new PageInfo(projects, pageSize);
        return page;
    }

    @RequestMapping("/updateProjectStatus")
    public void updateProjectStatus(@RequestParam String projectId, @RequestParam int operaCode){
        projectServer.updateProjectStatus(projectId, operaCode);
    }


    @RequestMapping("/selectProjectNameById")
    public String[] selectProjectNameById(@RequestParam String projectId){
        return projectServer.selectProjectNameById(projectId);
    }

}
